<template>
  <div class="ly-box pay">
    <div class="title">停车费</div>
    <div class="tips">{{info.warmPrompt||'--'}}</div>
    <div class="money">&yen;{{info.fee}}</div>
    <div class="line"></div>
    <div class="info">
      <div class="info-item">
        <div class="item-left">类型</div>
        <div class="item-right">{{info.carType}}</div>
      </div>
      <div class="info-item">
        <div class="item-left">车牌号</div>
        <div class="item-right">{{info.plate}}</div>
      </div>
      <div class="info-item">
        <div class="item-left">收费标准</div>
        <div class="item-right">{{info.feeDesc}}</div>
      </div>
      <div class="info-item">
        <div class="item-left">入场时间</div>
        <div class="item-right">{{info.inTime}}</div>
      </div>
      <!--<div class="info-item">-->
      <!--<div class="item-left">已停时长</div>-->
      <!--<div class="item-right"></div>-->
      <!--</div>-->
    </div>
    <div class="pay-btn" @click="handlePay">立即缴费</div>
  </div>
</template>

<script>
  import http from "../../http";
  import wx from "weixin-js-sdk"

  export default {
    name: 'pay',
    data() {
      return {
        info: {},
      };
    },
    created: function () {
      this.getCostInfo();
    },
    methods: {
      getCostInfo: function () {
        const boyd = {
          parkingId: this.$route.query.parkingId,
          plate: this.$route.query.plate,
        };
        http.get("/communityApps/parkpay/costInfo", boyd).then(res => {
          if (res.data.code == 20000) {
            this.info = res.data.data;
          } else {
            this.$dialog.toast({
              mes: res.data.message,
              timeout: 1500
            });
          }
        });

      },
      handlePay: function () {
        const params = {
          parkingId: this.$route.query.parkingId,
          plate: this.info.plate,
        };

        http.post("/communityApps/parkpay/weixinCost", params).then(res => {
          if (res.data.code == 20000) {

              // 微信支付
              wx.chooseWXPay({
                timestamp: res.data.data.payResult.timeStamp,// 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                nonceStr: res.data.data.payResult.nonceStr, // 支付签名随机串，不长于 32 位
                package: res.data.data.payResult.packageValue, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
                signType: res.data.data.payResult.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
                paySign: res.data.data.payResult.paySign, // 支付签名
                success: () => {
                  // 支付成功后的回调函数
                  this.$dialog.toast({
                    mes: '支付成功',
                    timeout: 2000,
                    icon: 'success',
                    callback: () => {
                      // this.$router.push("/propertyPay/roomList");
                      // this.$dialog.alert({mes: '给你一次重来的机会！'});
                    }
                  });

                }
              });


          } else {
            this.$dialog.toast({
              mes: res.data.message,
              timeout: 1500
            });
          }
        });
      },
    }
  }
  ;
</script>

<style scoped lang="scss">
  .pay {
    .title {
      width: 100%;
      text-align: center;
      color: #000;
      font-size: 0.36rem;
      height: 1rem;
      line-height: 1rem;
      background: #fff;
    }
    .tips {
      font-size: 0.24rem;
      color: #999;
      background: #fff;
      text-align: center;
    }
    .money {
      width: 100%;
      height: 2.4rem;
      background: #fff;
      text-align: center;
      font-size: 1rem;
      line-height: 2.4rem;
    }
    .line {
      width: 6.8rem;
      height: 1px;
      background: #666;
      margin: 0 auto;
    }
    .info {
      width: 100%;
      height: auto;
      background: #fff;
      padding: 0.4rem 0;
      border-bottom: 1px solid #999;
      .info-item {
        width: 6.8rem;
        height: 0.6rem;
        line-height: 0.6rem;
        font-size: 0.32rem;
        margin: 0 auto;
        .item-left {
          float: left;
          padding-right: 10px;
        }
        .item-right {
          color: #333;
        }
      }
    }
    .pay-btn {
      width: 6.8rem;
      height: 0.8rem;
      line-height: 0.8rem;
      background: #04ab02;
      margin: 0.4rem auto;
      border-radius: 0.1rem;
      color: #fff;
      text-align: center;
    }
  }
</style>
